#include <string>
#include <iostream>
using std::cout;
using std::endl;
using std::string;

class Student{
public:
    //以后遇到自定义类型对象作为函数参数
    //首先想到const引用形式
    //如果要改变这个对象的内容再去掉const
    Student(int age, const string & name)
    : _age(age)
    , _name(name)
    {
        cout << "Student(int,const string&)" << endl;
    }

    //严格要求destroy函数只能调用一次
    void destroy(){ 
        /* if(this && destroyNum == 0){ */
        if(this){
            /* destroyNum++; */
            delete this;
            /* this = nullptr; */
        }
    }
private:
    ~Student(){
        cout << "~Student()" << endl;
    }

    int _age;
    string _name;
    /* int destroyNum = 0; */
};

void test1(){
    string str0("cpp");
    string str = "hello";
    string str2 = "world";
    str2 = "wangdao";
    cout << str2 << endl;
    cout << sizeof(string) << endl;
}

void test0(){
    /* Student stu(21,"bob"); */
    Student * pstu = new Student(22,"tom");
    /* delete pstu; */
    pstu->destroy();
    /* pstu->destroy(); */
    pstu = nullptr;

    Student * pstu2 = nullptr;
    pstu2->destroy();
}

int main(void){
    test0();
    return 0;
}
